home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tk8.0 / tests / imgPPM.test < prev    next >
Encoding:
Text File  |  1997-08-15  |  6.1 KB  |  142 lines  |  [TEXT/ALFA]

  1. # This file is a Tcl script to test out the code in tkImgFmtPPM.c,
  2. # which reads and write PPM-format image files for photo widgets.
  3. # The files is organized in the standard fashion for Tcl tests.
  4. #
  5. # Copyright (c) 1994-1997 Sun Microsystems, Inc.
  6. #
  7. # See the file "license.terms" for information on usage and redistribution
  8. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  9. #
  10. # SCCS: @(#) imgPPM.test 1.13 97/06/20 14:27:59
  11.  
  12. if {[info procs test] != "test"} {
  13.     source defs
  14. }
  15.  
  16. foreach i [winfo children .] {
  17.     destroy $i
  18. }
  19. wm geometry . {}
  20. raise .
  21.  
  22. eval image delete [image names]
  23.  
  24. proc put {file data} {
  25.     set f [open $file w]
  26.     fconfigure $f -translation lf
  27.     puts -nonewline $f $data
  28.     close $f
  29. }
  30.  
  31. test imgPPM-1.1 {FileReadPPM procedure} {
  32.     put test.ppm "P6\n0 256\n255\nabcdef"
  33.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  34. } {1 {PPM image file "test.ppm" has dimension(s) <= 0}}
  35. test imgPPM-1.2 {FileReadPPM procedure} {
  36.     put test.ppm "P6\n-2 256\n255\nabcdef"
  37.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  38. } {1 {PPM image file "test.ppm" has dimension(s) <= 0}}
  39. test imgPPM-1.3 {FileReadPPM procedure} {
  40.     put test.ppm "P6\n10 0\n255\nabcdef"
  41.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  42. } {1 {PPM image file "test.ppm" has dimension(s) <= 0}}
  43. test imgPPM-1.4 {FileReadPPM procedure} {
  44.     put test.ppm "P6\n10 -2\n255\nabcdef"
  45.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  46. } {1 {PPM image file "test.ppm" has dimension(s) <= 0}}
  47. test imgPPM-1.5 {FileReadPPM procedure} {
  48.     put test.ppm "P6\n10 20\n256\nabcdef"
  49.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  50. } {1 {PPM image file "test.ppm" has bad maximum intensity value 256}}
  51. test imgPPM-1.6 {FileReadPPM procedure} {
  52.     put test.ppm "P6\n10 20\n0\nabcdef"
  53.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  54. } {1 {PPM image file "test.ppm" has bad maximum intensity value 0}}
  55. test imgPPM-1.7 {FileReadPPM procedure} {
  56.     put test.ppm "P6\n10 10\n255\nabcdef"
  57.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  58. } {1 {error reading PPM image file "test.ppm": not enough data}}
  59. test imgPPM-1.8 {FileReadPPM procedure} {
  60.     put test.ppm "P6\n5 4\n255\n01234567890123456789012345678901234567890123456789012345678"
  61.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  62. } {1 {error reading PPM image file "test.ppm": not enough data}}
  63. test imgPPM-1.9 {FileReadPPM procedure} {
  64.     put test.ppm "P6\n5 4\n150\n012345678901234567890123456789012345678901234567890123456789"
  65.     list [catch {image create photo p1 -file test.ppm} msg] $msg \
  66.         [image width p1] [image height p1]
  67. } {0 p1 5 4}
  68.  
  69. catch {image delete p1}
  70. put test.ppm "P6\n5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
  71. image create photo p1 -file test.ppm
  72. test imgPPM-2.1 {FileWritePPM procedure} {
  73.     list [catch {p1 write not_a_dir/bar/baz/gorp} msg] [string tolower $msg] \
  74.         [string tolower $errorCode]
  75. } {1 {couldn't open "not_a_dir/bar/baz/gorp": no such file or directory} {posix enoent {no such file or directory}}}
  76. test imgPPM-2.2 {FileWritePPM procedure} {
  77.     catch {unset data}
  78.     p1 write test2.ppm
  79.     set fd [open test2.ppm]
  80.     set data [read $fd]
  81.     close $fd
  82.     set data
  83. } {P6
  84. 5 4
  85. 255
  86. 012345678901234567890123456789012345678901234567890123456789}
  87.  
  88. test imgPPM-3.1 {ReadPPMFileHeader procedure} {
  89.     catch {image delete p1}
  90.     put test.ppm "#   \n#\n#\nP6\n#\n##\n5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
  91.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  92. } {0 p1}
  93. test imgPPM-3.2 {ReadPPMFileHeader procedure} {
  94.     catch {image delete p1}
  95.     put test.ppm "P6\n5\n 4                                                                        255\n012345678901234567890123456789012345678901234567890123456789"
  96.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  97. } {0 p1}
  98. test imgPPM-3.3 {ReadPPMFileHeader procedure} {
  99.     catch {image delete p1}
  100.     put test.ppm "P6\n#                                                                      asdfasdf\n5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
  101.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  102. } {0 p1}
  103. test imgPPM-3.4 {ReadPPMFileHeader procedure} {
  104.     catch {image delete p1}
  105.     put test.ppm "P6 \n5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
  106.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  107. } {0 p1}
  108. test imgPPM-3.5 {ReadPPMFileHeader procedure} {
  109.     catch {image delete p1}
  110.     put test.ppm "P5\n5 4\n255\n01234567890123456789"
  111.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  112. } {0 p1}
  113. test imgPPM-3.6 {ReadPPMFileHeader procedure} {
  114.     catch {image delete p1}
  115.     put test.ppm "P3\n5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
  116.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  117. } {1 {couldn't recognize data in image file "test.ppm"}}
  118. test imgPPM-3.7 {ReadPPMFileHeader procedure} {
  119.     catch {image delete p1}
  120.     put test.ppm "P6x\n5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
  121.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  122. } {1 {couldn't recognize data in image file "test.ppm"}}
  123. test imgPPM-3.8 {ReadPPMFileHeader procedure} {
  124.     catch {image delete p1}
  125.     put test.ppm "P6\nxy5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
  126.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  127. } {1 {couldn't recognize data in image file "test.ppm"}}
  128. test imgPPM-3.9 {ReadPPMFileHeader procedure} {
  129.     catch {image delete p1}
  130.     put test.ppm "P6\n5\n255\n!012345678901234567890123456789012345678901234567890123456789"
  131.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  132. } {1 {couldn't recognize data in image file "test.ppm"}}
  133. test imgPPM-3.10 {ReadPPMFileHeader procedure} {
  134.     catch {image delete p1}
  135.     put test.ppm "P6\n5 4\nzz255\n012345678901234567890123456789012345678901234567890123456789"
  136.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  137. } {1 {couldn't recognize data in image file "test.ppm"}}
  138.  
  139. removeFile test.ppm
  140. removeFile test2.ppm
  141. eval image delete [image names]
  142.